const { SECRET } = require('../config/config');
const jwt = require('jsonwebtoken');

module.exports = (req, res, next) => {

    let token = req.get('token');
    if (!token) {
        return res.json({
            code: 2003,
            message: 'not token',
            data: null
        })
    }

    jwt.verify(token, SECRET, (err, data) => {
        if (err) {
            return res.json({
                code: 2003,
                message: '效验失败',
                data: null
            })
        };

        req.user = data;
        next();
    })
}